// src/stores/ui.js
import { defineStore } from 'pinia'

export const useUiStore = defineStore('ui', {
  state: () => ({
    toastVisible: false,
    toastMessage: '',
    toastType: 'info', // 'success' | 'error' | 'info'
    _timer: null,
  }),
  actions: {
    showToast(message, type = 'info', duration = 2500) {
      this.toastMessage = message
      this.toastType = type
      this.toastVisible = true
      if (this._timer) {
        clearTimeout(this._timer)
      }
      this._timer = setTimeout(() => {
        this.toastVisible = false
        this._timer = null
      }, duration)
    },
    hideToast() {
      if (this._timer) {
        clearTimeout(this._timer)
        this._timer = null
      }
      this.toastVisible = false
    }
  }
})